package chuishop.yiqimaicai.controller;

import chuishop.yiqimaicai.pojo.Addgoods_body;
import chuishop.yiqimaicai.pojo.Addgoods_header;
import chuishop.yiqimaicai.pojo.GoodsHouse;
import chuishop.yiqimaicai.pojo.HouseInfo;
import chuishop.yiqimaicai.service.GoodsHouseService;
import chuishop.yiqimaicai.service.HouseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class HouseInfoController {

    @Autowired
    private HouseInfoService houseInfoService;
    @RequestMapping("findAllHouseInfo")
    @ResponseBody
    public List<HouseInfo> findAllHouseInfo(){
        List<HouseInfo> list=houseInfoService.findAllHouseInfo();
        return list;
    }

    @RequestMapping("addHouseInfo")
    @ResponseBody
    public Map<Object,Object> addHouseInfo(@RequestBody HouseInfo houseInfo){

        Map<Object,Object> result=new HashMap<>();
        if(houseInfoService.addHouseInfo(houseInfo)){
            result.put("status", "200");
            result.put("msg", "添加成功");
        } else {
            result.put("status", "500");
            result.put("msg", "添加失败");
        }
        return result;
    }

    @RequestMapping("delHouseInfo")
    @ResponseBody
    public Map<Object,Object> delHouseInfo(String ids){

        String strid[]=ids.split(",");
        Map<Object,Object> result=new HashMap<>();

        if(houseInfoService.delHouseInfo(strid)){
            result.put("status","200");
            result.put("msg","删除成功");
        }else {
            result.put("status","400");
            result.put("msg","删除失败");
        }
        return result;
    }


    @RequestMapping("updataHouseInfo")
    @ResponseBody
    public Map<Object,Object> updataHouseInfo(@RequestBody HouseInfo houseInfo){
        Map<Object,Object> result=new HashMap<>();
        if (houseInfoService.updataHouseInfo(houseInfo)){
            result.put("status","200");
            result.put("mag","添加成功");


        }else {
            result.put("status","500");
            result.put("msg","添加失败");
        }
        return result;
    }

    @RequestMapping("findHouseInfoBygname")
    @ResponseBody
    public List<HouseInfo> findHouseInfoBygname(String gname){

        List<HouseInfo> list=houseInfoService.findHouseInfoBygname(gname);

        return list;
    }
    @RequestMapping("getAddgoodsbodyId")
    @ResponseBody
    public List<Addgoods_body> getAddgoodsbodyId(){
        List<Addgoods_body> list=houseInfoService.getAddgoodsbodyId();
        return list;
    }

    @RequestMapping("getGoodsHouseid")
    @ResponseBody
    public List<GoodsHouse> getGoodsHouseid(){
        List<GoodsHouse> list=houseInfoService.getGoodsHouseid();
        return list;
    }

    @RequestMapping("getAddgoodsheadersid")
    @ResponseBody
    public List<Addgoods_header> getAddgoodsheadersid(){
        List<Addgoods_header> list=houseInfoService.getAddgoodsheadersid();
        return list;
    }
}
